package com.menggudf.controller;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.menggudf.model.ResultModel;
import com.menggudf.model.SystemAdminModel;
import com.menggudf.service.LinkAricleService;

/**
 * 文章链接
 * 
 * @author Administrator
 * 
 */
@Controller
@RequestMapping("linkAricle")
public class LinkAricleController {

	@Autowired
	private LinkAricleService linkAricleService;

	@RequestMapping("toSaveLinkAricle")
	@ResponseBody
	public ResultModel toSaveLinkAricle(HttpServletRequest request,
			HttpServletResponse response, HttpSession httpSession,
			@RequestParam(value = "title") String title,
			@RequestParam(value = "linkAricle") String linkAricle,
			@RequestParam(value = "organization") String organization,
			@RequestParam(value = "source") String source) {
		SystemAdminModel model = (SystemAdminModel) httpSession
				.getAttribute("SystemAdminModel");
		String userName = model.getAdminName();
		ResultModel resultModel = linkAricleService.toSaveLinkAricle(title,
				linkAricle, organization, source, userName);
		return resultModel;
	}
	
	@RequestMapping("getLinkAricleList")
	@ResponseBody
	public Map<String, Object> getLinkAricleList(
	        @RequestParam(value="title",required=false) String title,
	        @RequestParam(value="source",required=false) String source,
            @RequestParam(value="startTime",required=false) Date startTime,
            @RequestParam(value="endTime",required=false) Date endTime,
            @RequestParam("limit") int pageSize,
            @RequestParam("offset") int offset){
        return linkAricleService.getLinkAricleList(title,source,startTime,endTime,pageSize,offset);
	    
	}
	
	@RequestMapping("deleteLinkAricle")
    @ResponseBody
    public ResultModel deleteLinkAricle(
            @RequestParam("id") Integer id){
        return linkAricleService.deleteLinkAricle(id);
        
    }
	
}
